<template>
  <div class="page-leveladd">
    <pk-dialog :title="title" @confirm="confirm" @onClose="onClose" width="500px">
      <div class="mt-12 mb-12">
        <pk-form :formConfig="formConfig" labelPosition="top" ref="myForm"></pk-form>
      </div>
    </pk-dialog>
  </div>
</template>

<script setup>
import { ref, defineEmits, defineProps, onMounted } from 'vue'
import pkDialog from '@/components/pkui/pk-dialog/pk-dialog.vue'
import pkForm from '@/components/pkui/pk-form/pk-form.vue'
import { accountSetPwd } from '@/api/api'
const emit = defineEmits(['confirm', 'onClose'])
import { AES_Encrypt } from '@/utils/3des'
const props = defineProps({
  curData: {
    type: Object,
    default: () => {}
  }
})
const title = ref('修改密码')
const myForm = ref(null)
const formConfig = ref([ 
  {
    label: '密码',
    type: 'input',
    prop: 'password',
    showPassword: true
  },
  // {
  //   label: '邮箱',
  //   type: 'input',
  //   prop: 'email'
  // }, 
  // {
  //   label: '性别',
  //   type: 'radio',
  //   prop: 'sex',
  //   options: [
  //     {
  //       label: '男',
  //       value: 1
  //     },
  //     {
  //       label: '女',
  //       value: 2
  //     }
  //   ]
  // },  
])


const onClose = () => {
  emit('onClose')
}

const postAdd = (data) => {
  accountSetPwd({
    ...data,
    password: AES_Encrypt(data.password),
    id: props.curData.id
  }).then(res => {
    emit('confirm')
  })
}

const confirm = () => {
  myForm.value.submitForm().then(res => {
    postAdd(res)
  })
}
onMounted(() => {})

</script>

<style lang="scss" scoped>

</style>